package com.myz.rabbitmq.study3;

import com.myz.rabbitmq.utils.RabbitMqUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.MessageProperties;

import java.nio.charset.StandardCharsets;
import java.util.Scanner;


public class Producer_TASK {
    // 队列名称
    public static final String TASK_QUEUE_NAME = "ack_queue";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();
        // 声明队列
        boolean persistence = true; // 队列是否持久化
        channel.queueDeclare(TASK_QUEUE_NAME,persistence,false,false,null);
        // 从控制台输入信息
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String ms = sc.next();
            // 消息持久化
            // 将channel.basicPublish的第三个参数设置为MessageProperties.PERSISTENT_TEXT_PLAIN就可以实现一定程度的消息持久化
            channel.basicPublish("",TASK_QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN,ms.getBytes(StandardCharsets.UTF_8));
//            System.out.println("生产者发出消息:"+ms);
        }
    }
}
